﻿namespace Tuxedo.Compile
{
	internal class ReturnStatement : CodeLine
	{
		private Expression value;

		public ReturnStatement(Expression value)
		{
			this.value = value;
		}

		public static CodeLine Parse(TokenStream tokens)
		{
			tokens.PopExpected("return");
			Expression expression = null;
			if (!tokens.IsNext(";"))
			{
				expression = Expression.ParseExpression(tokens);
			}

			tokens.PopExpected(";");

			return new ReturnStatement(expression);
		}
	}
}
